# home page and login
import pymysql
from flask import Blueprint, render_template, request, redirect, url_for
from flask import Blueprint, request
from sqlalchemy import func, distinct
from app.models import Book
from app.models import Borrow
from app.models import Admin
from .response import Response
import pandas as pd

bp = Blueprint('user', __name__, url_prefix='/')

@bp.route('', methods=['GET', 'POST'])
def index():
    if request.method == 'GET':
        return render_template('login.html')
    else:
            username = request.form['username']
            admin = Admin.query.filter_by(username=username).first()
            if admin:
                context = {
                    'books': admin,
                }
                return redirect(url_for('AllBooks.AllBooks', **context))

            borrow = Borrow.query.filter_by(username=username).first()
            if borrow:
                context = {
                    'books': borrow,
                }
                return redirect(url_for('borrower.AllBooks', **context))

@bp.route('/sample', methods=['GET', 'POST'])
def sample():
    return render_template('ssss.html')
